/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package woowcrawler;

/**
 *
 * @author Deise
 */
import java.io.BufferedReader;
import woowcrawler.html.*;
import java.net.URL;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Artigo {
    private String Abstract;
    private ArrayList<String> Autores;
    private String Pages;
    private String ISBN;
    private String Titulo;
    private ArrayList<String> Tags;
    private WoowDocument doc;

    public Artigo(String link) throws Exception
    {
        try {
            URL url = new URL(link);
            BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
            String documento = "";
            String aux = "";
            while ((aux = br.readLine()) != null) {
                documento += aux;
            }
            //o documento HTML não é valido, iPhode
            Matcher m = Pattern.compile("<html[^<>]*>").matcher(documento);
            if (!m.find()) {
                documento = "<" + documento.substring(documento.indexOf("html"));
            }
            doc = new WoowDocument(documento);
            Autores = new ArrayList<String>();
            Tags = new ArrayList<String>();
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            doc=null;
        }

       
    }
    

    /**
     * @return the Abstract
     */
    public String getAbstract() {
        return Abstract;
    }

    /**
     * @param Abstract the Abstract to set
     */
    public void setAbstract(String Abstract) {
        this.Abstract = Abstract;
    }

    /**
     * @return the Autores
     */
    public ArrayList<String> getAutores() {
        return Autores;
    }

    /**
     * @param Autores the Autores to set
     */
    public void setAutores(ArrayList<String> Autores) {
        this.Autores = Autores;
    }

    public void setAutor(String Autor)
    {
        this.Autores.add(Autor);
    }
    /**
     * @return the Pages
     */
    public String getPages() {
        return Pages;
    }

    /**
     * @param Pages the Pages to set
     */
    public void setPages(String Pages) {
        this.Pages = Pages;
    }

    /**
     * @return the ISBN
     */
    public String getISBN() {
        return ISBN;
    }

    /**
     * @param ISBN the ISBN to set
     */
    public void setISBN(String ISBN) {
        this.ISBN = ISBN;
    }

    /**
     * @return the Titulo
     */
    public String getTitulo() {
        return Titulo;
    }

    /**
     * @param Titulo the Titulo to set
     */
    public void setTitulo(String Titulo) {
        this.Titulo = Titulo;
    }

    /**
     * @return the Tags
     */
    public ArrayList<String> getTags() {
        return Tags;
    }

    /**
     * @param Tags the Tags to set
     */
    public void setTags(ArrayList<String> Tags) {
        this.Tags = Tags;
    }

    public void setTag(String Tag)
    {
        this.Tags.add(Tag);
    }
    /**
     * @return the doc
     */
    public WoowDocument getDoc() {
        return doc;
    }

    /**
     * @param doc the doc to set
     */
    public void setDoc(WoowDocument doc) {
        this.doc = doc;
    }
}
